package com.intech.android.demo.cms.dao.impl;

import com.intech.android.demo.cms.bo.Group;
import com.intech.android.demo.cms.dao.interfaces.GroupDAO;
import org.hibernate.Criteria;
import org.hibernate.Session;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class GroupHibernateDAO extends CommonDAO implements GroupDAO
{
    public Group getById(Integer id)
    {
        return (Group) session.get(Group.class, id);
    }

    public void save(Group group)
    {
        session.saveOrUpdate(group);
    }

    public void delete(Group group)
    {
        session.delete(group);
    }


    public List<Group> getAll()
    {
        Criteria criteria = session.createCriteria(Group.class);
        List list = criteria.list();

        return list;
    }

    public List<Group> getListById(List<Integer> ids)
    {
        List<Group> groups = new ArrayList<Group>();

        Iterator iterator = ids.iterator();
        while (iterator.hasNext())
        {
            Integer id = (Integer) iterator.next();
            Group group = getById(id);
            groups.add(group);
        }
        return groups;
    }
}
